#include <string>
#include "stdafx.h"
#include "CppUnitTest.h"
#include "../Tenta-2014-12-14-3,4/bounded_vector.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace UnitTestBoundedVector
{		
	TEST_CLASS(UnitTestBoundedVector)
	{
	public:
		
		TEST_METHOD(TestBoundedVectorConstructor)
		{
			bounded_vector bv1();
			bounded_vector bv2('a', 'z');
		}

		TEST_METHOD(TestBoundedVectorSize)
		{
			bounded_vector bv('a', 'z');
			Assert::AreEqual(26, bv.get_size());
		}

		TEST_METHOD(TestBoundedLowHighIndex)
		{
			bounded_vector bv('a', 'z');
			Assert::AreEqual(97, bv.get_lowIndex());
			Assert::AreEqual(122, bv.get_highIndex());
		}

		TEST_METHOD(TestBoundedVectorSetBounds)
		{
			bounded_vector bv;
			bv.set_bounds('a', 'z');
			Assert::AreEqual(97, bv.get_lowIndex());
			Assert::AreEqual(122, bv.get_highIndex());
			Assert::AreEqual(26, bv.get_size());
		}

		TEST_METHOD(TestBoundedVectorArrayOperator)
		{
			bounded_vector bv('a', 'z');
			for (char c = 'a'; c <= 'z'; c++)
				Assert::AreEqual(0, bv[c]);
			bv['a']++;
			Assert::AreEqual(1, bv['a']);
			bv['a']++;
			bv['z']++;
			bv['g']++;
			Assert::AreEqual(2, bv['a']);
			Assert::AreEqual(1, bv['g']);
			Assert::AreEqual(1, bv['z']);
		}

		TEST_METHOD(TestBoundedVectorCopyConstructor)
		{
			bounded_vector bv('a', 'c');
			bv['a'] = 3;
			bv['b'] = 1;
			bv['c']++;
			bounded_vector bv2(bv);
			Assert::AreEqual(bv.get_highIndex(), bv2.get_highIndex());
			Assert::AreEqual(bv.get_lowIndex(), bv2.get_lowIndex());
			Assert::AreEqual(bv.get_size(), bv2.get_size());
			for (char c = 'a'; c <= 'c'; c++)
				Assert::AreEqual(bv[c], bv2[c]);
		}

		TEST_METHOD(TestBoundedVectorCopyAssignment)
		{
			bounded_vector bv('a', 'c');
			bv['a'] = 3;
			bv['b'] = 1;
			bv['c']++;
			bounded_vector bv2('a', 'd');
			bv2['a'] = 32;
			bv2['b'] = 12;
			bv2['c'] = 89;
			bv2['d'] = 54;
			bv2 = bv;
			Assert::AreEqual(bv.get_highIndex(), bv2.get_highIndex());
			Assert::AreEqual(bv.get_lowIndex(), bv2.get_lowIndex());
			Assert::AreEqual(bv.get_size(), bv2.get_size());
			for (char c = 'a'; c <= 'c'; c++)
				Assert::AreEqual(bv[c], bv2[c]);
		}

		TEST_METHOD(TestBoundedVectorAddOperator)
		{
			bounded_vector bv1('a', 'c');
			bv1['a'] = 1;
			bv1['b'] = 1;
			bv1['c'] = 1;
			bounded_vector bv2('a', 'c');
			bv2['a'] = 2;
			bv2['b'] = 2;
			bv2['c'] = 2;
			
			bounded_vector bv3 = bv1 + bv2;

			for (char c = 'a'; c <= 'c'; c++)
				Assert::AreEqual(3, bv3[c]);
		}

		TEST_METHOD(TestBoundedVectorTotalSum)
		{
			bounded_vector bv1('a', 'c');
			bv1['a'] = 1;
			bv1['b'] = 1;
			bv1['c'] = 1;
			bounded_vector bv2('a', 'c');
			bv2['a'] = 2;
			bv2['b'] = 2;
			bv2['c'] = 2;

			bounded_vector bv3 = bv1 + bv2;
			Assert::AreEqual(3, bv1.total_sum());
			Assert::AreEqual(6, bv2.total_sum());
			Assert::AreEqual(9, bv3.total_sum());
		}

		TEST_METHOD(TestBoundedVectorPrint)
		{
			bounded_vector bv1('a', 'c');
			bv1['a'] = 1;
			bv1['b'] = 2;
			bv1['c'] = 3;
			std::string s = "1,2,3";
			Assert::AreEqual(s, bv1.print());
		}

		TEST_METHOD(TestBoundedVectorIterator)
		{
			bounded_vector bv('a', 'c');
			int n = 1;
			for (auto &i : bv)
				i = n++;
			n = 1;
			for (char c = 'a'; c <= 'c'; c++)
				Assert::AreEqual(n++, bv[c]);

		}
	};
}